package com.dqp.cslggroup.JWXT;

import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.UI.BaseActivity;
import com.just.agentweb.AgentWeb;
import com.just.agentweb.AgentWebView;

public class jwxtWeb extends BaseActivity {
    private WebView mWebView;
    private String url = "https://webvpn.cslg.edu.cn/https/77726476706e69737468656265737421f3f652d224236457300d8db9d6562d/cas/login?service=https%3A%2F%2Fcas.cslg.edu.cn%2F";
    private ProgressBar pb;
    private LinearLayout mErrorView;
    private boolean loadError = false;
    private AgentWeb agentWeb;
    private AgentWebView agentWebView;
    private LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jwxt_web);
        linearLayout = findViewById(R.id.lin_web);
        agentWeb = AgentWeb.with(this)
                .setAgentWebParent(linearLayout, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready()
                .go("http://www.jd.com");


    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (agentWeb.handleKeyEvent(keyCode, event)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    protected void onPause() {
        agentWeb.getWebLifeCycle().onPause();
        super.onPause();

    }

    @Override
    protected void onResume() {
        agentWeb.getWebLifeCycle().onResume();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        agentWeb.getWebLifeCycle().onDestroy();
        super.onDestroy();
    }
//
//    @SuppressLint("SetJavaScriptEnabled")
//    public void seting() {
//        mWebView = findViewById(R.id.web);
//        mWebView.clearCache(true);
//        mWebView.getSettings().setJavaScriptEnabled(true);
//        pb = findViewById(R.id.w_pb);
//        mWebView.setWebChromeClient(new WebChromeClient() {
//            @Override
//            public void onProgressChanged(WebView view, int newProgress) {
//                if (newProgress == 100) {
//                    pb.setVisibility(View.GONE);//加载完网页进度条消失
//                } else {
//                    pb.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
//                    pb.setProgress(newProgress);//设置进度值
//                }
//            }
//        });
////        WebSettings settings = mWebView.getSettings();
////        settings.setDomStorageEnabled(true);
////        settings.setUseWideViewPort(true);
////        settings.setLoadWithOverviewMode(true);
////        settings.setAllowContentAccess(true); // 是否可访问Content Provider的资源，默认值 true
////        settings.setAllowFileAccess(true);    // 是否可访问本地文件，默认值 true
////        // 是否允许通过file url加载的Javascript读取本地文件，默认值 false
////        settings.setAllowFileAccessFromFileURLs(false);
////        // 是否允许通过file url加载的Javascript读取全部资源(包括文件,http,https)，默认值 false
////        settings.setAllowUniversalAccessFromFileURLs(false);
//////        settings.setJavaScriptEnabled(true);
////        settings.setSupportZoom(false);
//
//        mWebView.setWebViewClient(new WebViewClient(){
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//                return super.shouldOverrideUrlLoading(view, request);
//            }
//        });
//        mWebView.setWebViewClient(new NewWebViewClient());
//
//        mWebView.loadUrl(url);
//    }
//
//    class NewWebViewClient extends WebViewClient{
//        @Override
//        public void onPageStarted(WebView view, String url, Bitmap favicon) {
//            super.onPageStarted(view, url, favicon);
//        }
//
//        @Override
//        public void onPageFinished(WebView view, String url) {
//            //添加Cookie获取操作
//            CookieManager cookieManager = CookieManager.getInstance();
//            final String cookieStr = cookieManager.getCookie(url);
//            Log.e("Fetch Cookie: " , cookieStr);
//            if(cookieStr!=null){
//
//                Thread workThread = new Thread(){
//                    @Override
//                    public void run() {
//                        //Todo: 持久化Cookie到本地
//
//                    }
//                };
//                workThread.start();
//            }
//            super.onPageFinished(view, url);
//        }
//
//        @Override
//        public boolean shouldOverrideUrlLoading(WebView view, String url) {
//            //返回值是true的时候WebView打开，为false则系统浏览器或第三方浏览器打开。
//            //如果要下载页面中的游戏或者继续点击网页中的链接进入下一个网页的话，重写此方法下，不然就会跳到手机自带的浏览器了，而不继续在你这个webview里面展现了
//            view.loadUrl(url);
//            return true;
//        }
//
//        @Override
//        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
//            super.onReceivedError(view, request, error);
//        }
//
//    }
}
